package pratima;

import java.io.FileInputStream;
import java.io.FileNotFoundException;

import training.exception.InvalidArgumentException;


public class ExceptionDemo {
	
	public int divide (int a, int b) throws InvalidArgumentException{
		if(b==0){
			throw new InvalidArgumentException("Invalid value");
		}
		return a/b;
	}
	
	public static void main(String[] args) {
		ExceptionDemo demo = new ExceptionDemo();
		try {
			System.out.println(demo.divide(4, 0));
		} catch (InvalidArgumentException e1) {
			//multiple excpetions can be handled in single statement in java 7
			//Done before: InvalidArgumentException | ArithmeticException
			System.out.println("Arithmatic exception "+e1.getMessage());
			
			//If you are using catch block always do some process
		}//This is runtime excpetion
		finally {
			System.out.println("This block always executes");
		}
		
		try {
			FileInputStream fis = new FileInputStream("input.txt");
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		
	}
	
	//array out of bound is runtime exception - unchecked exception
	//You can  have nested try catch block
}

/*exceptions(can be handled) and errors (unrecoverable)
 * Exception are two types - which extends exception--compile time errors
 * other extends runtimeExcpetion, this is unchecked exception
 * All these are under throwable*/
